<?php  
namespace Home\Controller;
use \Think\Controller;
class WapController extends Controller{

	public function __construct(){

		parent::__construct();
		$time = time();
		$this->assign('time',$time);
		$map['id'] = I('get.id','intval');
        $res = M('category')->where($map)->find();
        if(!$res){

            $map['id'] = 1;
            $res = M('category')->where($map)->find();
        }

        if($res['pid'] != 0){
           
            $map['id'] = $res['pid'];
            $logo = M('category')->where($map)->find();
        }else{

            $logo = $res;
        }
        $list = M('category')->where(array('pid'=>$logo['id']))->select();

        foreach($list as $key=>$val){

            $list2[] = $val['id'];
        }
        if(in_array(I('get.id'), $list2)){

            $judge = I('get.id');
        }else{

            $judge = $list[0]['id'];
        }
        foreach($list as $key=>$val){

            if($val['id']==$judge){

                $position=$val;
            }
        }
        $this->assign('logo',$logo);
        $this->assign('list',$list);
        $this->assign('judge',$judge);
        $this->assign('position',$position);
	}

	public function header(){

		$this->display();
	}
	public function footer(){

		$this->display();
	}

	public function category(){
           $map['pid'] = $this->judge;
		if($this->logo['id']==5){
           
           $img = M('detail')->where($map)->select();
           $this->assign('img',$img);
           $this->display('product');
        }else if($this->logo['id']==2){

           if($map['pid'] ==8){

           	$this->display('jianjie');
           }
		}else{

			$this->display();
		}
	}
}
?>

